/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.icad.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Gabriel Bran gbran.u@gmail.com
 */
@Entity
@Table(name = "catalogo_contable")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CatalogoContable.findAll", query = "SELECT c FROM CatalogoContable c"),
    @NamedQuery(name = "CatalogoContable.findByIglesia", query = "SELECT c FROM CatalogoContable c WHERE c.catalogoContablePK.iglesia = :iglesia"),
    @NamedQuery(name = "CatalogoContable.findByCodigo", query = "SELECT c FROM CatalogoContable c WHERE c.catalogoContablePK.codigo = :codigo"),
    @NamedQuery(name = "CatalogoContable.findByNombre", query = "SELECT c FROM CatalogoContable c WHERE c.nombre = :nombre"),
    @NamedQuery(name = "CatalogoContable.findByDescripcion", query = "SELECT c FROM CatalogoContable c WHERE c.descripcion = :descripcion"),
    @NamedQuery(name = "CatalogoContable.findByFechaCreacion", query = "SELECT c FROM CatalogoContable c WHERE c.fechaCreacion = :fechaCreacion")})
public class CatalogoContable implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CatalogoContablePK catalogoContablePK;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "nombre")
    private String nombre;
    @Size(max = 255)
    @Column(name = "descripcion")
    private String descripcion;
    @Basic(optional = false)
    @NotNull
    @Column(name = "fecha_creacion")
    @Temporal(TemporalType.DATE)
    private Date fechaCreacion;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "catalogoContable")
    private List<DetalleTransaccion> detalleTransaccionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "catalogoContable")
    private List<CatalogoContable> catalogoContableList;
    @JoinColumns({
        @JoinColumn(name = "iglesia", referencedColumnName = "iglesia", insertable = false, updatable = false),
        @JoinColumn(name = "cuenta_padre", referencedColumnName = "codigo")})
    @ManyToOne(optional = false)
    private CatalogoContable catalogoContable;
    @JoinColumn(name = "iglesia", referencedColumnName = "id", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Iglesia iglesia1;

    public CatalogoContable() {
    }

    public CatalogoContable(CatalogoContablePK catalogoContablePK) {
        this.catalogoContablePK = catalogoContablePK;
    }

    public CatalogoContable(CatalogoContablePK catalogoContablePK, String nombre, Date fechaCreacion) {
        this.catalogoContablePK = catalogoContablePK;
        this.nombre = nombre;
        this.fechaCreacion = fechaCreacion;
    }

    public CatalogoContable(int iglesia, int codigo) {
        this.catalogoContablePK = new CatalogoContablePK(iglesia, codigo);
    }

    public CatalogoContablePK getCatalogoContablePK() {
        return catalogoContablePK;
    }

    public void setCatalogoContablePK(CatalogoContablePK catalogoContablePK) {
        this.catalogoContablePK = catalogoContablePK;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public Date getFechaCreacion() {
        return fechaCreacion;
    }

    public void setFechaCreacion(Date fechaCreacion) {
        this.fechaCreacion = fechaCreacion;
    }

    @XmlTransient
    public List<DetalleTransaccion> getDetalleTransaccionList() {
        return detalleTransaccionList;
    }

    public void setDetalleTransaccionList(List<DetalleTransaccion> detalleTransaccionList) {
        this.detalleTransaccionList = detalleTransaccionList;
    }

    @XmlTransient
    public List<CatalogoContable> getCatalogoContableList() {
        return catalogoContableList;
    }

    public void setCatalogoContableList(List<CatalogoContable> catalogoContableList) {
        this.catalogoContableList = catalogoContableList;
    }

    public CatalogoContable getCatalogoContable() {
        return catalogoContable;
    }

    public void setCatalogoContable(CatalogoContable catalogoContable) {
        this.catalogoContable = catalogoContable;
    }

    public Iglesia getIglesia1() {
        return iglesia1;
    }

    public void setIglesia1(Iglesia iglesia1) {
        this.iglesia1 = iglesia1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (catalogoContablePK != null ? catalogoContablePK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CatalogoContable)) {
            return false;
        }
        CatalogoContable other = (CatalogoContable) object;
        if ((this.catalogoContablePK == null && other.catalogoContablePK != null) || (this.catalogoContablePK != null && !this.catalogoContablePK.equals(other.catalogoContablePK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.icad.entity.CatalogoContable[ catalogoContablePK=" + catalogoContablePK + " ]";
    }
    
}
